home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
scilab
/
demos
/
pendulum
/
pendule.dem
< prev
next >
Wrap
Text File
|
1999-09-16
|
3KB
|
152 lines
mode(0)
xselect();xbasc();
//
getf('SCI/demos/pendulum/macros.sci','c')
//
x_message('the cart')
// ----------------
//
xselect();
dpnd()
//
// equations
//----------
//state =[x x' theta theta']
//
mb=0.1;mc=1;l=0.3;m=4*mc+mb;//constants
//
x_message('open loop simulation');
//
y0=[0;0;0.1;0];
// y=ode(y0,0,0.03*(1:180),ivpd);
y=read('SCI/demos/pendulum/yy',4,180,'(e12.6)');
xbasc();
anim(y(1,:),y(3,:),1);
//
x_message('linearization')
//
x0=[0;0;0;0];u0=0;
[f,g,h,j]=lin(pendu,x0,u0);
pe=syslin('c',f,g,h,j);ssprint(pe)
//
x_message('checking the result');
//
f1=[0 1 0 0
0 0 -3*mb*9.81/m 0
0 0 0 1
0 0 6*(mb+mc)*9.81/(m*l) 0];
g1=[0 ; 4/m ; 0 ; -6/(m*l)];
h1=[1 0 0 0
0 0 1 0];
norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)
x_message('analysis');
//---------
//unstable system !
//
spec(f)
//
//controlability
//
n=contr(f,g)
//
//observability
//
m1=contr(f',h(1,:)')
//
[m2,t]=contr(f',h(2,:)')
//
x_message('synthesis of a stabilizing controller');
//-------------------------------------------------
//
//pole placement technique
//only x and theta are observed : contruction of an observer
//to estimate the state : z'=(f-k*h)*z+k*y+g*u
//
to=0.1; //
k=ppol(f',h',-ones(4,1)/to)' //observer gain
//
//verification
//
// norm( poly(f-k*h,'z')-poly(-ones(4,1)/to,'z'))
//
kr=ppol(f,g,-ones(4,1)/to) //compensator gain
//
x_message('linear system pendulum-observer-compensator')
//---------------------------------------------
//
//state: [x x-z]
//
ft=[f-g*kr -g*kr
0*f f-k*h]
gt=[g;0*g];
ht=[h,0*h];
pr=syslin('c',ft,gt,ht);
// closed loop dynamics:
spec(pr(2))
//transfer matrix representation
hr=clean(ss2tf(pr),1.d-10)
//frequency analysis
// black(pr,0.01,100,['position','theta'])
g_margin(pr(1,1))
//
x_message('sampled system')
//---------------
//
t=to/5;
prd=dscr(pr,t);
spec(prd(2))
//
x_message('impulse response')
//-----------------
//
x0=[0;0;0;0;0;0;0;0];
u(1,180)=0;u(1,1)=1;
y=flts(u,prd,x0);
[xxr,yyr]=xgetech();
[xxf]=xget("font");
xset("wdim",850,650);
xbasc();
xset("font",2,0);
xsetech([0,0,0.5,0.5]);
plot2d1("enn",1,y(1,:)');xtitle(' ','t',' position');
xsetech([0.5,0,0.5,0.5]);
plot2d1("enn",1,y(2,:)');xtitle(' ','t',' theta');
xsetech([0,0.5,1.0,0.5]);
anim(100*y(1,:),100*y(2,:),1),
xsetech(xxr);
xset("font",xxf(1),xxf(2));
//
x_message('compensation of the non linear system');
//--------------------------------------
//
//simulation
//
t0=0;t1=t*(1:125);
x0=[0 0 0.4 0 0 0 0 0]'; //
yd=ode(x0,t0,t1,regu);
//
x_message('non linear simulation')
[xxr,yyr]=xgetech();
[xxf]=xget("font");
xbasc();
xset("font",2,0);
xsetech([0,0,0.5,0.5]);
plot2d(t1',(kr*yd(5:8,:))');xtitle(' ','time','control');
xsetech([0.5,0,0.5,0.5]);
plot2d([t1;t1]',yd([3,7],:)',[-1,-2],"121",'theta@theta estimated');
xsetech([0,0.5,1.0,0.5]);
anim(yd(1,:),yd(3,:),1)
xsetech(xxr);
xset("font",xxf(1),xxf(2));
xbasc();
xset("wdim",610,455);